package com.safeneeds.linguimana.entity.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;



import java.util.Map;

import com.safeneeds.linguimana.entity.PortNewsCate;
import com.safeneeds.linguimana.entity.dao.IPortNewsCateDao;
import com.safeneeds.util.base.BaseHibernateDao;
import com.safeneeds.util.other.StringUtil;

/**
 * 新闻分类
 * 
 * @author gaof
 * @date 2017年2月7日
 */
public class PortNewsCateDao extends BaseHibernateDao<PortNewsCate, String>
		implements IPortNewsCateDao {

	/**
	 * 获取新闻分类列表
	 * 
	 * @return
	 */
	@Override
	public List<PortNewsCate> listNewsCate() {
		return this.getEntities("From PortNewsCate order by sort");
	}

	/**
	 * 添加新闻分类
	 * 
	 * @param cate
	 */
	@Override
	public void addNewsCate(PortNewsCate cate) {
		this.saveEntity(cate);
	}

	/**
	 * 通过id获取新闻分类
	 * 
	 * @param cateId
	 * @return
	 */
	@Override
	public PortNewsCate getNewsCateById(String cateId) {
		return this.findById(cateId);
	}

	/**
	 * 删除所有新闻分类
	 */
	@Override
	public void delAllNewsCate() {
		this.executeQuery("delete from port_news_cate");
	}

	/**
	 * 通过父id获取新闻分类列表
	 * 
	 * @param cateId
	 * @return
	 */
	@Override
	public List<PortNewsCate> listCateByPId(String cateId) {
		return this.getEntities("from PortNewsCate where pid = '"
				+ StringUtil.addQuote(cateId) + "'");
	}

	/**
	 * 批量删除新闻分类
	 * 
	 * @param cateList
	 */
	@Override
	public void delNewsCateList(List<PortNewsCate> cateList) {
		this.deleteAll(cateList);
	}

	/**
	 * 通过新闻分类id删除新闻分类对应关系
	 * 
	 * @param cateId
	 */
	@Override
	public void delNewsCateMapByCateId(String cateId) {
		this.executeQuery("delete from port_news_cate_map where cate_id = '"
				+ StringUtil.addQuote(cateId) + "'");
	}

	/**
	 * 删除所有新闻分类对应关系
	 */
	@Override
	public void delAllNewsCateMap() {
		this.executeQuery("delete from port_news_cate_map");
	}

	/**
	 *获取新闻分类信息
	 *@param 
	 * @return
	 */
	@Override

	public List<PortNewsCate> listCateByPId_1(int i,String index) {
		String sql="select * from(select * from port_news_cate where cate_index='"+index+"' and pid='0' order by sort ) where rownum <="+i;
		return this.getSQLQuery(sql, PortNewsCate.class);	
	}

	/**
	 * 获取新闻分类专题栏目
	 * @param i 个数
	 * @param name 分类栏目
	 * @return
	 */
	@Override
	public List<PortNewsCate> getChildCateImage(int i,String name) {
	
		String hsql = "from PortNewsCate p2 "
				+ "where p2.pid=(select p.cateId from PortNewsCate p "
				+ "where p.name='"+name+"'and p.pid='0') "
				+ "order by p2.sort";
		return this.getEntitiesPage(hsql, 1, i);
	}


}
